package com.ruoyi.web.controller.bill;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BillMonthStatistic;
import com.ruoyi.system.service.IBillMonthStatisticService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 账单每月统计Controller
 * 
 * @author ruoyi
 * @date 2023-03-17
 */
@Controller
@RequestMapping("/bill/statistic")
public class BillMonthStatisticController extends BaseController
{
    private String prefix = "bill/statistic";

    @Autowired
    private IBillMonthStatisticService billMonthStatisticService;

    @RequiresPermissions("bill:statistic:view")
    @GetMapping()
    public String statistic()
    {
        return prefix + "/statistic";
    }

    /**
     * 查询账单每月统计列表
     */
    @RequiresPermissions("bill:statistic:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BillMonthStatistic billMonthStatistic)
    {
        startPage();
        List<BillMonthStatistic> list = billMonthStatisticService.selectBillMonthStatisticList(billMonthStatistic);
        return getDataTable(list);
    }

    /**
     * 导出账单每月统计列表
     */
    @RequiresPermissions("bill:statistic:export")
    @Log(title = "账单每月统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BillMonthStatistic billMonthStatistic)
    {
        List<BillMonthStatistic> list = billMonthStatisticService.selectBillMonthStatisticList(billMonthStatistic);
        ExcelUtil<BillMonthStatistic> util = new ExcelUtil<BillMonthStatistic>(BillMonthStatistic.class);
        return util.exportExcel(list, "账单每月统计数据");
    }

    /**
     * 新增账单每月统计
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存账单每月统计
     */
    @RequiresPermissions("bill:statistic:add")
    @Log(title = "账单每月统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BillMonthStatistic billMonthStatistic)
    {
        return toAjax(billMonthStatisticService.insertBillMonthStatistic(billMonthStatistic));
    }

    /**
     * 修改账单每月统计
     */
    @RequiresPermissions("bill:statistic:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BillMonthStatistic billMonthStatistic = billMonthStatisticService.selectBillMonthStatisticById(id);
        mmap.put("billMonthStatistic", billMonthStatistic);
        return prefix + "/edit";
    }

    /**
     * 修改保存账单每月统计
     */
    @RequiresPermissions("bill:statistic:edit")
    @Log(title = "账单每月统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BillMonthStatistic billMonthStatistic)
    {
        return toAjax(billMonthStatisticService.updateBillMonthStatistic(billMonthStatistic));
    }

    /**
     * 删除账单每月统计
     */
    @RequiresPermissions("bill:statistic:remove")
    @Log(title = "账单每月统计", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(billMonthStatisticService.deleteBillMonthStatisticByIds(ids));
    }
}
